"""Workflow: zopista_workflow
"""

# Copyright (c) 2005 by TcheZope.org
#

# Generator: ArchGenXML Version 1.4 devel 4
#            http://sf.net/projects/archetypes/
#
# GNU General Public Licence (GPL)
# 
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA
#
__author__    = '''Fabiano Weimar dos Santos <xiru@xiru.org>, Jean Rodrigo Ferri
<jeanrodrigoferri@yahoogroups.com>, Rafahela Bazzanella
<rafabazzanella@yahoo.com.br>'''
__docformat__ = 'plaintext'
__version__   = '$ Revision 0.0 $'[11:-2]

from Products.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowTool import addWorkflowFactory
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
from Products.ExternalMethod.ExternalMethod import ExternalMethod

##code-section create-workflow-module-header #fill in your manual code here
##/code-section create-workflow-module-header


productname = 'PloneZopista'

def setupzopista_workflow(self, workflow):
    """Define the zopista_workflow workflow.
    """

    workflow.setProperties(title='zopista_workflow')

    ##code-section create-workflow-setup-method-header #fill in your manual code here
    ##/code-section create-workflow-setup-method-header


    for s in ['private', 'pending', 'published']:
        workflow.states.addState(s)

    for t in ['retract', 'submit', 'publish', 'reject']:
        workflow.transitions.addTransition(t)

    for v in ['review_history', 'comments', 'time', 'actor', 'action']:
        workflow.variables.addVariable(v)

    for p in ['View', 'Modify portal content', 'Change portal events', 'Access contents information', 'List folder contents', 'Add Profissional Content', 'Add Empresa Content', 'Add Oportunidade Content', 'Add CasoUso Content', 'Add portal content']:
        workflow.addManagedPermission(p)
 
    for l in []:
        if not l in workflow.worklists.objectValues():
            workflow.worklists.addWorklist(l)

    ## Initial State

    workflow.states.setInitialState('private')

    ## States initialization

    stateDef = workflow.states['private']
    stateDef.setProperties(title="""private""",
                           transitions=['publish', 'submit'])
    stateDef.setPermission('View',
                           0,
                           ['Manager', 'Owner'])
    stateDef.setPermission('Modify portal content',
                           0,
                           ['Manager', 'Owner'])
    stateDef.setPermission('Change portal events',
                           0,
                           ['Manager', 'Owner'])
    stateDef.setPermission('Access contents information',
                           0,
                           ['Manager', 'Owner'])

    stateDef = workflow.states['pending']
    stateDef.setProperties(title="""pending""",
                           transitions=['publish', 'reject', 'retract'])
    stateDef.setPermission('View',
                           0,
                           ['Manager', 'Owner', 'Reviewer'])
    stateDef.setPermission('Modify portal content',
                           0,
                           ['Manager', 'Reviewer'])
    stateDef.setPermission('Change portal events',
                           0,
                           ['Manager', 'Reviewer'])
    stateDef.setPermission('Access contents information',
                           0,
                           ['Manager', 'Owner', 'Reviewer'])

    stateDef = workflow.states['published']
    stateDef.setProperties(title="""published""",
                           transitions=['reject', 'retract'])
    stateDef.setPermission('View',
                           1,
                           ['Anonymous', 'Manager'])
    stateDef.setPermission('Modify portal content',
                           0,
                           ['Manager'])
    stateDef.setPermission('Change portal events',
                           0,
                           ['Manager'])
    stateDef.setPermission('List folder contents',
                           1,
                           ['Anonymous'])
    stateDef.setPermission('Add Profissional Content',
                           1,
                           ['Member'])
    stateDef.setPermission('Add Empresa Content',
                           1,
                           ['Member'])
    stateDef.setPermission('Add Oportunidade Content',
                           1,
                           ['Member'])
    stateDef.setPermission('Add CasoUso Content',
                           1,
                           ['Member'])
    stateDef.setPermission('Add portal content',
                           1,
                           ['Member'])
    stateDef.setPermission('Access contents information',
                           1,
                           ['Anonymous', 'Manager'])

    ## Transitions initialization

    transitionDef = workflow.transitions['retract']
    transitionDef.setProperties(title="""retract""",
                                new_state_id="""private""",
                                trigger_type=1,
                                script_name="""""",
                                after_script_name="""""",
                                actbox_name="""retract""",
                                actbox_url="""""",
                                actbox_category="""workflow""",
                                props={'guard_roles': 'Owner'},
                                )

    transitionDef = workflow.transitions['submit']
    transitionDef.setProperties(title="""submit""",
                                new_state_id="""pending""",
                                trigger_type=1,
                                script_name="""""",
                                after_script_name="""""",
                                actbox_name="""submit""",
                                actbox_url="""""",
                                actbox_category="""workflow""",
                                props={'guard_roles': 'Owner'},
                                )

    transitionDef = workflow.transitions['publish']
    transitionDef.setProperties(title="""publish""",
                                new_state_id="""published""",
                                trigger_type=1,
                                script_name="""""",
                                after_script_name="""""",
                                actbox_name="""publish""",
                                actbox_url="""""",
                                actbox_category="""workflow""",
                                props={'guard_permissions': 'Review portal content'},
                                )

    transitionDef = workflow.transitions['reject']
    transitionDef.setProperties(title="""reject""",
                                new_state_id="""private""",
                                trigger_type=1,
                                script_name="""""",
                                after_script_name="""""",
                                actbox_name="""reject""",
                                actbox_url="""""",
                                actbox_category="""workflow""",
                                props={'guard_permissions': 'Review portal content'},
                                )

    ## State Variable
    workflow.variables.setStateVar('review_state')

    ## Variables initialization
    variableDef = workflow.variables['review_history']
    variableDef.setProperties(description="""Provides access to workflow history""",
                              default_value="""""",
                              default_expr="""state_change/getHistory""",
                              for_catalog=0,
                              for_status=0,
                              update_always=0,
                              props={'guard_permissions': 'Request review; Review portal content'})

    variableDef = workflow.variables['comments']
    variableDef.setProperties(description="""Comments about the last transition""",
                              default_value="""""",
                              default_expr="""python:state_change.kwargs.get('comment', '')""",
                              for_catalog=0,
                              for_status=1,
                              update_always=1,
                              props=None)

    variableDef = workflow.variables['time']
    variableDef.setProperties(description="""Time of the last transition""",
                              default_value="""""",
                              default_expr="""state_change/getDateTime""",
                              for_catalog=0,
                              for_status=1,
                              update_always=1,
                              props=None)

    variableDef = workflow.variables['actor']
    variableDef.setProperties(description="""The ID of the user who performed the last transition""",
                              default_value="""""",
                              default_expr="""user/getId""",
                              for_catalog=0,
                              for_status=1,
                              update_always=1,
                              props=None)

    variableDef = workflow.variables['action']
    variableDef.setProperties(description="""The last transition""",
                              default_value="""""",
                              default_expr="""transition/getId|nothing""",
                              for_catalog=0,
                              for_status=1,
                              update_always=1,
                              props=None)

    ## Worklists Initialization


    # WARNING: below protected section is deprecated.
    # Add a tagged value 'worklist' with the worklist name to your state(s) instead.
    ##code-section create-workflow-setup-method-footer #fill in your manual code here
    ##/code-section create-workflow-setup-method-footer



def createzopista_workflow(self, id):
    """Create the workflow for PloneZopista.
    """
    
    ob = DCWorkflowDefinition(id)
    setupzopista_workflow(self, ob)
    return ob

addWorkflowFactory(createzopista_workflow,
                   id='zopista_workflow',
                   title='zopista_workflow')

##code-section create-workflow-module-footer #fill in your manual code here
##/code-section create-workflow-module-footer

